/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.core.object;


/**
 *
 * @author sunil
 */
public class ObjectCopy implements Cloneable {

    private String name;
    private Sam sample;
    
    public ObjectCopy(String name) {
        sample = new Sam();
        this.name = name;
        sample.setName(name);
    }

    public void setName(String name){
        this.name = name;
        sample.setName(name);
    }
    
    public static void main(String[] args) throws CloneNotSupportedException {
        ObjectCopy obj1 = new ObjectCopy("sunil");

        System.out.println("1 NAME        -----" + obj1.name);
        System.out.println("1 SAMPLE NAME -----" + obj1.sample.getName());

        ObjectCopy obj2 = (ObjectCopy)obj1.clone();
        obj2.setName("singh");

        System.out.println("2 NAME        -----" + obj2.name);
        System.out.println("2 SAMPLE NAME -----" + obj2.sample.getName());

        System.out.println("1 NAME        -----" + obj1.name);
        System.out.println("1 SAMPLE NAME -----" + obj1.sample.getName());
        
    }
    
}
